// XXX Switch to using function literals (closures).
package main

import (
    "flag"
    "fmt"
    "strconv"
)


type FibState struct {
    n0  int
    n1  int
}


func newFib() *FibState {
    return &FibState{1, 0}
}


func (state *FibState) next() (to_return int) {
    to_return = (*state).n1

    fib := (*state).n0 + (*state).n1
    (*state).n1 = (*state).n0
    (*state).n0 = fib

    return
}


func main() {
    flag.Parse()

    fib, err := strconv.Atoi(flag.Arg(0))

    if err != nil {
        panic("crap")
    }

    state := newFib()

    for x := 0; x <= fib; x++ {
        fmt.Printf("%v ", state.next())
    }

    fmt.Println("...")
}
